package xinyu.customer.widget;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import xinyu.customer.R;
import xinyu.customer.widget.dialog.ProgressWheel;

public class CustomProgressDialog extends CustomPrtDialog {

    protected LinearLayout mLinearLayout;
    protected TextView mTextView;
    protected Context mContext;
    /**
     * 显示的信息.
     */
    private String mMessage = null;
    /**
     * 是否取消.
     */
    private boolean mCancelable = false;

    /**
     * 构造函数
     *
     * @param context    上下文
     * @param message    信息
     * @param cancelable 是否可物理返回取消
     * @param isShow     是否展示.
     */
    public CustomProgressDialog(Context context, String message,
                                boolean cancelable, boolean isShow) {

        super(context, R.style.CustomProgressDialog);
        //        super(context);//背景变暗
        this.mMessage = message;
        this.mCancelable = cancelable;
        mContext = context;
        if (isShow) {
            show();
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setCanceledOnTouchOutside(false);
        setCancelable(mCancelable);
        setContentView(R.layout.dialog_progress_layout);

        mTextView = (TextView) this
                .findViewById(R.id.dialog_progress_layout_tv_message);
        mLinearLayout = (LinearLayout) findViewById(R.id.dialog_ll);
        ProgressWheel progressWheel = findViewById(R.id.dialog_progress_layout_pb_message);
        if (!TextUtils.isEmpty(mMessage)) {
            mTextView.setText(mMessage);
        } else {
            mTextView.setVisibility(View.GONE);
        }
        progressWheel.setBarColor(0xFFFFFFFF);
    }

    /**
     * 设置背景.
     */
    public void setBackgroundTransparency() {

        if (mLinearLayout == null) {
            return;
        }
        mTextView.setTextColor(Color.BLACK);
        mLinearLayout.setBackgroundColor(getContext().getResources()
                .getColor(android.R.color.transparent));
    }
}
